﻿Imports NHibernate

Public Class DDD2
    Inherits EmptyInterceptor

    Public Overrides Function OnLoad(ByVal entity As Object, ByVal id As Object, ByVal state() As Object, ByVal propertyNames() As String, ByVal types() As NHibernate.Type.IType) As Boolean
        Console.WriteLine("OnLoad************************")
        'CriarInterface Abstract Repositorio
        Return MyBase.OnLoad(entity, id, state, propertyNames, types)
    End Function

    Public Overrides Function Instantiate(ByVal clazz As String, ByVal entityMode As NHibernate.EntityMode, ByVal id As Object) As Object
        Console.WriteLine("Instantiate************************")
        Return MyBase.Instantiate(clazz, entityMode, id)
    End Function

    Public Overrides Function OnSave(ByVal entity As Object, ByVal id As Object, ByVal state() As Object, ByVal propertyNames() As String, ByVal types() As NHibernate.Type.IType) As Boolean
        Console.WriteLine("OnSave************************")
        Return MyBase.OnSave(entity, id, state, propertyNames, types)
    End Function

End Class

Public Class DDD
    Implements IInterceptor

    Public Sub AfterTransactionBegin(ByVal tx As NHibernate.ITransaction) Implements NHibernate.IInterceptor.AfterTransactionBegin
        Console.WriteLine("AfterTransactionBegin*************")
    End Sub

    Public Sub AfterTransactionCompletion(ByVal tx As NHibernate.ITransaction) Implements NHibernate.IInterceptor.AfterTransactionCompletion
        Console.WriteLine("AfterTransactionCompletion*************")
    End Sub

    Public Sub BeforeTransactionCompletion(ByVal tx As NHibernate.ITransaction) Implements NHibernate.IInterceptor.BeforeTransactionCompletion
        Console.WriteLine("BeforeTransactionCompletion*************")
    End Sub

    Public Function FindDirty(ByVal entity As Object, ByVal id As Object, ByVal currentState() As Object, ByVal previousState() As Object, ByVal propertyNames() As String, ByVal types() As NHibernate.Type.IType) As Integer() Implements NHibernate.IInterceptor.FindDirty
        Console.WriteLine("FindDirty*************")
    End Function

    Public Function GetEntity(ByVal entityName As String, ByVal id As Object) As Object Implements NHibernate.IInterceptor.GetEntity
        Console.WriteLine("GetEntity " & entityName)
        Return id
    End Function

    Public Function GetEntityName(ByVal entity As Object) As String Implements NHibernate.IInterceptor.GetEntityName
        Return entity.GetType.Name
    End Function

    Public Function Instantiate(ByVal entityName As String, ByVal entityMode As NHibernate.EntityMode, ByVal id As Object) As Object Implements NHibernate.IInterceptor.Instantiate
        Console.WriteLine("Instanciando " & entityName)
        Return Nothing
    End Function

    Public Function IsTransient(ByVal entity As Object) As Boolean? Implements NHibernate.IInterceptor.IsTransient
        Console.WriteLine("IsTransient*************")
    End Function

    Public Sub OnCollectionRecreate(ByVal collection As Object, ByVal key As Object) Implements NHibernate.IInterceptor.OnCollectionRecreate
        Console.WriteLine("OnCollectionRecreate*************")
    End Sub

    Public Sub OnCollectionRemove(ByVal collection As Object, ByVal key As Object) Implements NHibernate.IInterceptor.OnCollectionRemove
        Console.WriteLine("OnCollectionRemove*************")
    End Sub

    Public Sub OnCollectionUpdate(ByVal collection As Object, ByVal key As Object) Implements NHibernate.IInterceptor.OnCollectionUpdate
        Console.WriteLine("OnCollectionUpdate*************")
    End Sub

    Public Sub OnDelete(ByVal entity As Object, ByVal id As Object, ByVal state() As Object, ByVal propertyNames() As String, ByVal types() As NHibernate.Type.IType) Implements NHibernate.IInterceptor.OnDelete
        Console.WriteLine("OnDelete*************")
    End Sub

    Public Function OnFlushDirty(ByVal entity As Object, ByVal id As Object, ByVal currentState() As Object, ByVal previousState() As Object, ByVal propertyNames() As String, ByVal types() As NHibernate.Type.IType) As Boolean Implements NHibernate.IInterceptor.OnFlushDirty
        Return True
    End Function

    Public Function OnLoad(ByVal entity As Object, ByVal id As Object, ByVal state() As Object, ByVal propertyNames() As String, ByVal types() As NHibernate.Type.IType) As Boolean Implements NHibernate.IInterceptor.OnLoad
        Console.WriteLine("Onload " & entity.GetType.Name)
        Return True
    End Function

    Public Function OnPrepareStatement(ByVal sql As NHibernate.SqlCommand.SqlString) As NHibernate.SqlCommand.SqlString Implements NHibernate.IInterceptor.OnPrepareStatement
        Return sql
    End Function

    Public Function OnSave(ByVal entity As Object, ByVal id As Object, ByVal state() As Object, ByVal propertyNames() As String, ByVal types() As NHibernate.Type.IType) As Boolean Implements NHibernate.IInterceptor.OnSave
        Return True
    End Function

    Public Sub PostFlush(ByVal entities As System.Collections.ICollection) Implements NHibernate.IInterceptor.PostFlush
        Console.WriteLine("PostFlush*************")
    End Sub

    Public Sub PreFlush(ByVal entities As System.Collections.ICollection) Implements NHibernate.IInterceptor.PreFlush
        Console.WriteLine("PreFlush*************")
    End Sub

    Public Sub SetSession(ByVal session As NHibernate.ISession) Implements NHibernate.IInterceptor.SetSession
        Console.WriteLine("SetSession*************")
    End Sub
End Class